<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper animated fadeInRight">
        <div class="row">
            <div>
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="signupForm">
                        	<input type="hidden" value="${role.arId }" id="rId" name="rId">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">名称：</label>
                                <div class="col-sm-8">
                                    <input id="arName" name="arName" value="${role.arName }" maxlength="20" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>必填</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">备注：</label>
                                <div class="col-sm-8">
                                    <textarea id="arRemark" name="arRemark" value="${role.arRemark }" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">${role.arRemark }</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="submit">保存</button>
                                    <button class="btn btn-primary" onclick="cancel();">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 全局js -->
    <script src="${pageContext.request.contextPath }/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="${pageContext.request.contextPath }/js/content.js?v=1.0.0"></script>
    <!-- jQuery Validation plugin javascript-->
    <script src="${pageContext.request.contextPath }/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/layer/layer.min.js"></script>
    <script type="text/javascript">
    $().ready(function () {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
            	arName: {
                    required: true,
                    remote: {
    					url: "${pageContext.request.contextPath}/admin/role/isExistName",
    					cache: false,            
    		            data:{
    		            		arName:function(){return $("#arName").val();},
    		            		rId:function(){return $("#rId").val();},
    		                 }
    				}
                }
            },
            messages: {
            	arName: {
            		required:icon + "请输入角色名称",
            		remote:icon + "名称已存在"}
                
            },
    		submitHandler: function(form) {
    			saveType();
    		}
        });
    });
    //保存
    function saveType(){
    	$.ajax({
            type: "POST",
            url: "${pageContext.request.contextPath}/admin/role/update",
            data: $('#signupForm').serialize(),
            dataType: "json",
            success: function(data){
            	if(data.code==1){
					layer.msg('修改成功!',{icon:1});
					setTimeout('cancel()',3000);
				}else if(data.code==0){
					layer.msg(data.message,{icon:0});
				}else{
					layer.msg('对不起!你没有权限!',{icon:0});
				}
            }
        });
    }
  	//取消
    function cancel(){
   	 	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);
    }
    </script>
</body>
</html>